package com.thd.kotlinapp.activity

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import com.thd.kotlinapp.R
import com.thd.kotlinapp.constant.Constants
import com.thd.kotlinapp.databinding.ActivitySchedulerBinding
import com.thd.kotlinapp.service.SchedulerService
import java.security.Provider.Service

class SchedulerActivity : AppCompatActivity() {

    private lateinit var schedulerBinder : ActivitySchedulerBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        schedulerBinder = DataBindingUtil.setContentView(this,R.layout.activity_scheduler)

        schedulerBinder.timePicker.setIs24HourView(true)

        schedulerBinder.yes.setOnClickListener {
            val contain : String = schedulerBinder.editContain.text.toString();
            if (contain == null || contain.isEmpty()){
                Toast.makeText(this,getString(R.string.please_input),Toast.LENGTH_SHORT).show()
                return@setOnClickListener
            }
            Constants.schedulerContain = contain
            Constants.schedulerTask = schedulerBinder.timePicker.hour.toString() + ":" + schedulerBinder.timePicker.minute.toString()
            Toast.makeText(this,getString(R.string.successful),Toast.LENGTH_SHORT).show()
        }

        val serviceScheduler = Intent(this,SchedulerService::class.java)

        schedulerBinder.startService.setOnClickListener {
            startService(serviceScheduler)
            Toast.makeText(this,getString(R.string.successful),Toast.LENGTH_SHORT).show()
        }

        schedulerBinder.returnButton.setOnClickListener {
            stopService(serviceScheduler)
            finish()
        }


    }
}